//
//  LCBMessageCell.m
//  UITableView
//
//  Created by Administrator on 2016/11/13.
//  Copyright © 2016年 Administrator. All rights reserved.
//

#import "LCBMessageCell.h"
#import "LCBMessage.h"
#import "Masonry.h"
#import "ICMediaManager.h"
#import "ICFileTool.h"



@interface LCBMessageCell()

@end

@implementation LCBMessageCell


+ (instancetype)cellWithTableView:(UITableView *)tableView reusableId:(NSString *)ID selectionStyle:(LCBMessageType)type SendMessageStyle:(ICChitChatMessageState )messagetype
{
    LCBMessageCell *cell = [[LCBMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.identifier = type;
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}


#pragma mark - UI

- (void)buildViews
{
    [self addSubview:self.timeLabel];
    NSLog(@"super buildViews");
}

#pragma mark - Constraint
- (void)setConstraint
{
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(5);
        make.centerX.equalTo(self.mas_centerX);
        make.width.mas_equalTo(250);
        // make.height.mas_equalTo(21);
    }];
    NSLog(@"super setConstraint");
}


-(UILabel *)timeLabel
{
    if(!_timeLabel)
    {
        _timeLabel = [[UILabel alloc] init];
        _timeLabel.backgroundColor = ICRGB(0xd3d2d2);
        _timeLabel.textColor = [UIColor whiteColor];
        _timeLabel.layer.masksToBounds = YES;
        _timeLabel.layer.cornerRadius = 5.0;
        _timeLabel.font = [UIFont systemFontOfSize:12];
        _timeLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _timeLabel;
}

//-(ICLCBMessageButton *)textButton
-(UIButton *)textButton
{
    if(!_textButton){
        _textButton = [[UIButton alloc]init];
        [_textButton setBackgroundImage:[UIImage imageNamedFromiComeSDKBundle:@"chat_recive_nor"] forState:UIControlStateNormal];
        [_textButton setBackgroundImage:[UIImage imageNamedFromiComeSDKBundle:@"chat_recive_press_pic"] forState:UIControlStateHighlighted];
    }
    return _textButton;
}

-(UIImageView *)iconView
{
    if(!_iconView)
    {
        _iconView = [[UIImageView alloc] init];
        _iconView.layer.masksToBounds = YES;
        _iconView.userInteractionEnabled = YES;
    }
    return _iconView;
}

- (UIImageView *)bgView
{
    if (!_bgView) {
        _bgView         = [[UIImageView alloc] init];
        _bgView.layer.cornerRadius  = 5;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)timeLabelhideTime:(LCBMessage *)message
{
    // 时间处理
    if (message.hideTime) { // 隐藏时间
        self.timeLabel.hidden = YES;
        [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(0);
        }];
    } else { // 显示时间
        NSDateFormatter *dateFormater = [[NSDateFormatter alloc] init];
        [dateFormater setDateFormat:@"yyyy-MM-dd HH:mm"];
        self.timeLabel.text = [dateFormater stringFromDate:[NSDate dateWithTimeIntervalSince1970:message.date/1000]];
        //[ICMessageHelper timeFormatWithDate:self.message.date];
        self.timeLabel.hidden = NO;
        [self.timeLabel sizeToFit];
        [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(self.timeLabel.frame.size.width+10);
            make.height.mas_equalTo(15);
        }];
    }
}

- (void)setMessage:(LCBMessage *)message
{
    _message = message;
    // 时间处理

    [self timeLabelhideTime:message];
    
}




@end
